<template>
	<view class="cart">
		<view class="header">
			购物车列表
		</view>
		<u-list :height="screenHeight">
			<view class="cartList">
				<view class="cartItem" v-for="(item,index) in cartList" :key="item.id">
					<!-- 选中 -->
					<text class="iconfont icon-xuanzhong" :class="{select:item.isSelected}" @click="isSelect(index)"></text>
					<!-- 商品信息 -->
					<view class="goods-item">
							<image class="img" :src="item.listPicUrl" mode=""></image>
							<view class="goods-info">
								<view class="goods-name">
									{{item.name}}
								</view>
								<view class="goods-price">
									￥{{item.retailPrice}}.00
								</view>
							</view>
					</view>
					<view class="changeNum">
						<uni-number-box v-model="vModelValue=item.count" :min='1' @change='changeNum(item)'></uni-number-box>
					</view>
				</view>	
			</view>
		</u-list>
		<view class="footer">
			<view class="footer-left">
				<text class="iconfont icon-xuanzhong" :class="{select:allSelect}" @click="allSelectFn"></text>
				<text class="change">已选择 {{select}}</text>
			</view>
			<view class="footer-right">
				<text class="sum">合计：￥{{priceSum}}</text>
				<text class="order">下单</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from "vuex"
	export default {
		data() {
			return {
				vModelValue:1,
				screenHeight:0
			}
		},
		methods: {
			...mapMutations('cart',['addGoodsItem','editGoodsItem','allEditGoodsItem']),
			//改变商品数量
			changeNum(item){
				this.addGoodsItem(item)
			},
			//勾选商品状态
			isSelect(index){
				this.editGoodsItem(index)
			},
			//全选功能
			allSelectFn(){
				this.allEditGoodsItem(this.allSelect)
			}
		},
		
		computed:{
			...mapState('cart',['cartList']),
			...mapGetters('cart',['select','allSelect','priceSum']),
		},
		mounted() {
			//获取页面高度
			this.screenHeight = uni.getSystemInfoSync().windowHeight - 90; //获取当前页面的高度
		}
	}
</script>

<style lang="scss">
	body{
		position: relative;

	}
	.cart{
		// height: 100vh;
		background-color: #f5f5f5;
		.header{
			width: 100%;
			height: 90rpx;
			text-align: left;
			line-height: 90rpx;
			padding-left: 30rpx;
		}
		.cartList{
			.cartItem{
				position: relative;
				background-color:white;
				margin-bottom: 10rpx;
				height: 172rpx;
				width: 100%;
				display: flex;
				padding: 20rpx;
				.changeNum{
					position: absolute;
					right: 80rpx;
					bottom: 30rpx;
					
				}
				.iconfont{
					font-size: 40rpx;
					line-height: 172rpx;
					&.select{
						color: #dc372a;
					}
					
				}
				.goods-item{
					display: flex;
					.img{
						height: 172rpx;
						width: 172rpx;
						margin: 0 45rpx;
					}
					.goods-info{
						.goods-name{
							font-size: 30rpx;
							margin: 20rpx;
						}
						.goods-price{
							font-size: 28rpx;
							padding-left: 16rpx;
							color: #bb2c08;
						}
					}
				}
			}
		}
		.footer{
			position: fixed;
			background-color: #f9ffff;
			bottom: 100rpx;
			width: 100%;
			height: 90rpx;
			display: flex;
			justify-content: space-between;
			.footer-left{
				.iconfont{
					font-size: 40rpx;
					line-height: 90rpx;
					margin: 0 20rpx;
					&.select{
						color: #dc372a;
					}
				}
				
			}
			.footer-right{
				display: flex;
				align-items: center;
				.sum{
					margin-right: 20rpx;
				}
				.order{
					display: block;
					width: 130rpx;
					height: 90rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #dc372a;
				}
			}
		}
	}
</style>
